import { VxeFormItemProps, VxeGridPropTypes } from '@gui-pkg/antdcomponents';
import { getAllStationData } from '@/api/information/rain';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import {getOptionselect} from "@/api/system/role";


const typeData = [
  {value: 1, label: '1小时'},
  {value: 3, label: '3小时'},
  {value: 6, label: '6小时'},
]
const townData = [

  {value: '大金镇', label: '大金镇'},
  {value: '四望镇', label: '四望镇'},
  {value: '梅川镇', label: '梅川镇'},
  {value: '花桥镇', label: '花桥镇'},
  {value: '田家镇街道', label: '田家镇街道'},
  {value: '余川镇', label: '余川镇'},
  {value: '大法寺镇', label: '大法寺镇'},
  {value: '刊江街道', label: '刊江街道'},
]

const statusData = [
  {value: 5, label: '5年一遇'},
  {value: 10, label: '10年一遇'},
]
const seriesData = [{value: 1, label: '启动'}, {value: 0, label: '关闭'}]
const allData = [{value: 1, label: '是'}, {value: 0, label: '否'}]
export const columns: VxeGridPropTypes.Columns = [
  {
    type:"checkbox",
    width:80
  },
  {
    title: '镇',
    field: 'town',
    align: 'center',
  },
  {
    title: '测站名称',
    field: 'stnm',
    align: 'center',
  },
  {
    title: '时段类型',
    field: 'type',
    align: 'center',
    formatter: ({cellValue}) => {
      const data: any = typeData?.find((item:any) => item.value === cellValue);
      return data?.label;
    }
  },
  {
    title: '高风险阈值(mm)',
    field: 'level1',
    align: 'center',
  },
  {
    title: '极高风险阈值(mm)',
    field: 'level2',
    align: 'center',
  },

  {
    title: '是否启用',
    field: 'series',
    align: 'center',
    slots: {
      default: ({ row }) => {
        const status = row.status;
        const enable = ~~status === 1;
        const color = enable ? 'green' : 'red';
        const text = enable ? '启用' : '停用';
        return h(Tag, { color: color }, () => text);
      },
    },
  },
  {
    title: '操作',
    align: 'center',
    slots: { default: 'action' },
  },
];

export const searchFormSchema: VxeFormItemProps[] = [
  {
    field: 'town',
    title: '镇',
    itemRender: {
      name: 'ASelect',
      props: {
        options: townData,
      },
    },
    span: 4,
  },
  {
    field: 'stnm',
    title: '测站名称',
    itemRender: {
      name: 'AInput',
    },
    span: 4,
  },
  {
    field: 'type',
    title: '时段类型',
    itemRender: {
      name: 'ASelect',
      props: {
        options: typeData,
      },
    },
    span: 4,
  },
  {
    span: 12,
    align: 'right',
    className: '!pr-0',
    itemRender: {
      name: 'AButtonGroup',
      children: [
        {
          props: { type: 'primary', content: '查询', htmlType: 'submit' },
          attrs: { class: 'mr-2' },
        },
        { props: { type: 'default', htmlType: 'reset', content: '重置' } },
      ],
    },
  },
];

export const formSchema = [
  {
    field: 'allStcd',
    label: '是否全部站点',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: allData
    },
  },
  {
    label: '站点',
    field: 'stcds',
    component: 'ApiSelect',
    componentProps: () => {
      return {
        api: () => new Promise((resolve) => {
          getAllStationData().then((res:any) => {
            console.log('-------',res);
            resolve(res);
          });
        }),
        mode: "multiple",
        fieldNames: {
          label: 'stnm',
          key: 'stcd',
          value: 'stcd',
        },
      };
    },
  },
  {
    field: 'type',
    label: '时段类型',
    component: 'Select',
    defaultValue: 1,
    componentProps: {
      options: typeData
    },
  },

  {
    field: 'level1',
    label: '高风险阈值(mm)',
    component: 'InputNumber',
  },
  {
    field: 'level2',
    label: '极高风险阈值(mm)',
    component: 'InputNumber',
  },

  {
    field: 'status',
    label: '是否启用',
    component: 'RadioButtonGroup',
    defaultValue: 1,
    componentProps: {
      options: seriesData
    },
  },
];
